﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ChiTietPhim : System.Web.UI.Page
{
    ClassPhim cp = new ClassPhim();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null)
        {
            DataList1.DataSource = cp.ChiTietPhim(Request.QueryString["idcd"]);
            DataList1.DataBind();
        }
        else
        {
            DataList1.DataSource = cp.ChiTietPhim(Request.QueryString["id"]);
            DataList1.DataBind();
        }
    }
    protected void DataList1_ItemCommand1(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "thue")
        {
            if (Session["user"] == null)
                Label8.Text = "Bạn phải đăng nhập để thuê đĩa";
            else
            {
                DataTable dtb;
                if (Session["GioHang"] == null)
                {
                    dtb = new DataTable();
                    dtb.Columns.Add("MaPhim", typeof(string));
                    dtb.Columns.Add("TenPhim", typeof(string));
                    dtb.Columns.Add("SoMuon", typeof(int));
                    dtb.Columns.Add("GiaThue", typeof(float));
                    dtb.Columns.Add("ThanhTien", typeof(float), "SoMuon*GiaThue");
                    dtb.PrimaryKey = new DataColumn[] { dtb.Columns[0] };
                    Session["GioHang"] = dtb;
                }
                else
                    dtb = (DataTable)Session["GioHang"];
                Label Ten = (Label)e.Item.FindControl("lbTenPhim");
                Label Gia = (Label)e.Item.FindControl("lbGiaThue");
                dtb.Rows.Add(e.CommandArgument.ToString(), Ten.Text, 1, Gia.Text);
                Session["GioHang"] = dtb;
                Label8.Text = "";
            }
        }
    }
}
